{extend name="public/base"/}
{block name="body"}
<title>添加/修改 - 设置 -</title>
<style type="text/css">
	.isshow{display:block;}
	.disshow{display:none;}
	.layui-upload-file{display:none;}
</style>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>设置管理<span class="c-gray en">&gt;</span> 设置 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<input type="hidden" class="input-text" value="{$data.id}" id="id" name="id">

		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">地址</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.address}" id="address" name="address">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">经纬度：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.lat_lng}" placeholder="经纬度;例如:30.527540,114.346430" id="lat_lng" name="lat_lng">
                     <a href="http://lbs.qq.com/tool/getpoint/" target="_blank">
                     <p class="dizhi">*点击获取地理位置</p></a>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">电话：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$data.telphone}" id="telphone" name="telphone">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">多图：</label>
			<div class="formControls col-xs-8 col-sm-9">
				
				<input type="hidden" name="facilities" class="multiple_show_img" value=""> 
				<div class="layui-upload">
				        <button type="button" class="layui-btn" id="multiple_img_upload">多图片上传</button>
				        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
				            <div class="layui-upload-list" id="div-slide_show">
            					{foreach $data.facilitiesarr as $value }
				            	<img src="{$value}"  title="点击删除" class="layui-upload-img" style="width: 100px;height: 100px;" onclick="delMultipleImgs(this)">
				            	{/foreach}
				            </div>
				        </blockquote>
				        <div style="font-size:10px;color:#999999;">(建议尺寸：700*400)</div>
				</div>

			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">简介：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<script id="editor" name="introduction" type="text/plain" style="width:100%;height:400px;">{:htmlspecialchars_decode($data.introduction)}</script>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">须知：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<script id="editor_tip" name="introduction" type="text/plain" style="width:100%;height:400px;">{:htmlspecialchars_decode($data.tip)}</script>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-3 col-sm-offset-2">
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script src="/static/lib/layui-v2.4.5/layui-v2.4.5/layui/layui.js"></script>
<script type="text/javascript">
	$(function(){
		var ue = UE.getEditor('editor');
		var ue = UE.getEditor('editor_tip');
	});

	var multiple_images = [];
	if("{$data.facilities}"){
		multiple_images = "{$data.facilities}".split(",");
        $('.multiple_show_img').val(multiple_images);
	}

    //单击图片删除图片 【注册全局函数】
    function delMultipleImgs(this_img){
    	console.log(this_img)
        //获取下标
        var subscript=$("#div-slide_show img").index(this_img);
    	console.log(subscript)
        //删除图片
        this_img.remove();
    	console.log(this_img)
        //删除数组
    	console.log(multiple_images)
        multiple_images.splice(subscript, 1);
    	console.log(multiple_images)
        //重新排序
        multiple_images.sort();
    	console.log(multiple_images)
        $('.multiple_show_img').val(multiple_images);
        //返回
        return ;
    }
    layui.use([ 'upload'], function () {
       
        var upload = layui.upload;
        //多图片上传
        upload.render({
            elem: '#multiple_img_upload'
            ,url: "{:url('uploadtmd')}"
            ,multiple: true
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#div-slide_show').append('<img src="'+ result +'" alt="'+ file.name +'" title="点击删除" class="layui-upload-img" style="width: 100px;height: 100px;" onclick="delMultipleImgs(this)">&nbsp;')
                });
            }
            ,done: function(res){
                //如果上传成功
                if (res.code == 200) {
                    //追加图片成功追加文件名至图片容器
                    multiple_images.push(res.photo);
                    $('.multiple_show_img').val(multiple_images);
                }else {
                    //提示信息
                   layer.msg(res.msg);
                }
            }
        });

    });
	$("#submit").click(function() {
		layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		var address=$("input[name=address]").val();
		var lat_lng=$("input[name=lat_lng]").val();
		var telphone=$("input[name=telphone]").val();
		var facilities=$("input[name=facilities]").val();
		var introduction=UE.getEditor('editor').getContent();
		var tip=UE.getEditor('editor_tip').getContent();
	    $.ajax({
		    type: 'POST',
		    url: "{:url('system_set')}",
		    data: {address:address,lat_lng:lat_lng,telphone:telphone,facilities:facilities,introduction:introduction,tip:tip},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	})
</script> 
{/block}